<!-- 订单管理-客户订单-销售订单 -->
<template>
  <pageHeader :title="title" :breadCrumb="breadCrumb" :show-back="true">
  </pageHeader>
  <div class="search-box">
    <div>
      <a-space>
        <a-input-search
          search-button
          v-model="NumberSearch"
          :style="{ width: '220px' }"
          placeholder="占用产品名"
          @search="Search"
        />

        <a-button type="outline" @click="reset">
          <template #icon>
            <icon-refresh />
          </template>
          <template #default>重置</template>
        </a-button>
      </a-space>
    </div>
    <div>
      <a-space>
        <a-button status="success">
          <template #icon>
            <icon-download />
          </template>
          <template #default>导入</template>
        </a-button>

        <a-button status="warning" @click="OrderDerive">
          <template #icon>
            <icon-export :rotate="-90" />
          </template>
          <template #default>导出</template>
        </a-button>
      </a-space>
    </div>
  </div>
  <div style="padding: 10px">
    <TableTurn :table-data="getData" ref="tableRef">
      <a-table-column :width="80" align="center">
        <template #title> 序号 </template>
        <template #cell="{ rowIndex }">
          {{ rowIndex + 1 }}
        </template>
      </a-table-column>
      <a-table-column
        :width="200"
        title="产品名称"
        align="center"
        data-index="name"
        :ellipsis="true"
        :tooltip="{
          position: 'top',
        }"
      >
      </a-table-column>
      <a-table-column
        :width="200"
        title="编号"
        align="center"
        data-index="number"
        :ellipsis="true"
        :tooltip="{
          position: 'top',
        }"
      >
      </a-table-column>
      <a-table-column
        :width="200"
        title="规格"
        align="center"
        data-index="spec"
        :ellipsis="true"
        :tooltip="{
          position: 'top',
        }"
      >
      </a-table-column>
      <a-table-column
        :width="200"
        title="关联订单编号"
        align="center"
        data-index="orderNumber"
      >
      </a-table-column>
      <a-table-column
        :width="200"
        title="占用数量"
        align="center"
        data-index="occupiedAmount"
      >
      </a-table-column>
      <a-table-column :width="100" fixed="right" title="操作" align="center">
        <template #title>
          <span>操作</span>
        </template>
        <template #cell="{ record }">
          <a-tooltip content="取消占用">
            <a-popconfirm
              content="确认取消占用？"
              type="error"
              @ok="del(record.id)"
            >
              <IconFont
                type="icon-delete"
                :size="26"
                :style="{
                  marginRight: '10px',
                  cursor: 'pointer',
                }"
              />
            </a-popconfirm>
          </a-tooltip>
        </template>
      </a-table-column>
    </TableTurn>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, ref, computed, onMounted } from 'vue';
  import { useRouter } from 'vue-router';
  import dayjs from 'dayjs';
  import {
    getoccupiedAll,
    putPoductOccupied,
  } from '@/api/order-management/client-order';

  const tableRef = ref();
  const title: string = '占用列表';
  const breadCrumb: string[] = ['订单管理', '客户订单', '占用列表'];
  const NumberSearch = ref();
  // 获取对应列表信息
  const getData = async (pageData?: any) => {
    try {
      let msg: any = {};
      if (NumberSearch.value) msg.name = NumberSearch.value;
      const res = await getoccupiedAll({
        ...pageData,
        ...msg,
      });

      return Promise.resolve(res);
    } catch (err: unknown) {
      console.log(err);
    }
  };

  const Search = () => {
    tableRef.value.refreshPaging();
    tableRef.value.loadData();
  };
  const reset = () => {
    NumberSearch.value = '';
    tableRef.value.refreshPaging();
    tableRef.value.loadData();
  };

  const del = async (id: number) => {
    await putPoductOccupied({ id, occupiedAmount: 0 });
    reset();
  };
</script>

<style scoped lang="less">
  // .sales-order {
  // }
  .search-box {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 0px 10px;
    margin-top: -7px;
  }

  :deep(.arco-space-item) {
    margin-top: 10px;
  }

  .status {
    display: flex;
    align-items: center;
    justify-content: center;

    p {
      width: 12px;
      height: 12px;
      border-radius: 50%;
      margin-right: 10px;
    }
  }

  :deep(.arco-tabs-content) {
    padding-top: 0px;
  }
  :deep(.arco-drawer-header) {
    background-color: rgb(232, 237, 250);
  }
</style>
